<template>
  <div class="top">
    <div class="title">{{ item.name }}</div>
    <div class="user">{{ item.manager }}</div>
    <el-dropdown @command="commandbj">
      <span>操作
        <i class="el-icon-arrow-down el-icon--right" />
      </span>
      <template #dropdown>
        <el-dropdown-menu>
          <el-dropdown-item command="add">添加子部门</el-dropdown-item>
          <el-dropdown-item
            v-if="!item.isTop"
            command="exit"
          >查看部门</el-dropdown-item>
          <el-dropdown-item
            v-if="!item.isTop"
            command="del"
          >删除部门</el-dropdown-item>
        </el-dropdown-menu>
      </template>
    </el-dropdown>
  </div>
</template>

<script>
export default {
  props: {
    item: {
      type: Object,
      default: () => ({}),
      required: true
    }
  },
  methods: {
    commandbj(command) {
      switch (command) {
        case 'add':
          this.$bus.$emit('add', true, this.item)
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.top {
  display: flex;
  .title {
    flex: 1;
  }
  .user {
    width: 120px;
    margin-right: 20px;
    text-align: right;
  }
}
</style>
